package com.gyx.metaldesigndemo.recycle;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;

/**
 * Created by Administrator on 2016/11/15.
 */

public class SimpleTouchHelperCallBack extends ItemTouchHelper.Callback {

    private RecyclerViewDraggedAdapter mAdapter;
    public SimpleTouchHelperCallBack(RecyclerViewDraggedAdapter mAdapter){
        this.mAdapter=mAdapter;
    }

    @Override
    public boolean isLongPressDragEnabled() {
        return super.isLongPressDragEnabled();
    }

    @Override
    public boolean isItemViewSwipeEnabled() {
        return super.isItemViewSwipeEnabled();
    }

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        int dragged=ItemTouchHelper.UP|ItemTouchHelper.DOWN;
        int swipe=ItemTouchHelper.END|ItemTouchHelper.START;
        return makeMovementFlags(dragged,swipe);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        mAdapter.onItemMove(viewHolder.getAdapterPosition(),target.getAdapterPosition());
        return true;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
        mAdapter.onItemDismiss(viewHolder.getAdapterPosition());
    }
}
